package com.example.demotest.demotest.handler;

import com.example.demotest.demotest.aspect.AnnotationRange;
import com.example.demotest.demotest.aspect.BigDecimalRange;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.math.BigDecimal;
import java.util.HashSet;
import java.util.regex.Pattern;

/**
 * @author x_weidanlang
 * @version 1.0
 * @date 2022/2/9 10:36
 *
 * ConstraintValidatorConstraintValidator<BigDecimalRange,Integer>，第二个参数类型与vo中要校验的类型一致，如果vo中是String，那么这里就是String
 */

public class BigDecimalValidatorHandler implements ConstraintValidator<BigDecimalRange, BigDecimal> {
    @Override
    public boolean isValid(BigDecimal param, ConstraintValidatorContext constraintValidatorContext) {
        Pattern pattern =Pattern.compile("^[-+]?\\d+(\\.\\d+)?$");
        if (pattern.matcher(param.toString()).find())
            return true;
        return false;
    }

}
